package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GoodtableCart;
import com.ruoyi.system.service.IGoodtableCartService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品购物车Controller
 * 
 * @author jlx
 * @date 2024-02-21
 */
@RestController
@RequestMapping("/system/cart")
public class GoodtableCartController extends BaseController
{
    @Autowired
    private IGoodtableCartService goodtableCartService;

    /**
     * 查询商品购物车列表
     */
    @PreAuthorize("@ss.hasPermi('system:cart:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodtableCart goodtableCart)
    {
        startPage();
        List<GoodtableCart> list = goodtableCartService.selectGoodtableCartList(goodtableCart);
        return getDataTable(list);
    }

    /**
     * 导出商品购物车列表
     */
    @PreAuthorize("@ss.hasPermi('system:cart:export')")
    @Log(title = "商品购物车", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodtableCart goodtableCart)
    {
        List<GoodtableCart> list = goodtableCartService.selectGoodtableCartList(goodtableCart);
        ExcelUtil<GoodtableCart> util = new ExcelUtil<GoodtableCart>(GoodtableCart.class);
        util.exportExcel(response, list, "商品购物车数据");
    }

    /**
     * 获取商品购物车详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cart:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodtableCartService.selectGoodtableCartById(id));
    }

    /**
     * 新增商品购物车
     */
    @PreAuthorize("@ss.hasPermi('system:cart:add')")
    @Log(title = "商品购物车", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodtableCart goodtableCart)
    {
        return toAjax(goodtableCartService.insertGoodtableCart(goodtableCart));
    }

    /**
     * 修改商品购物车
     */
    @PreAuthorize("@ss.hasPermi('system:cart:edit')")
    @Log(title = "商品购物车", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodtableCart goodtableCart)
    {
        return toAjax(goodtableCartService.updateGoodtableCart(goodtableCart));
    }

    /**
     * 删除商品购物车
     */
    @PreAuthorize("@ss.hasPermi('system:cart:remove')")
    @Log(title = "商品购物车", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodtableCartService.deleteGoodtableCartByIds(ids));
    }
}
